package com.mytijian.task.enums;

import com.mytijian.base.exception.BizException;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public enum  TaskStatusEnum {
    un_begin(0,"未开始"),
    processing(1, "执行中"),
    suspend(2, "暂停"),
    stop(3, "停止"),
    complete(4, "执行结束"),
    ;
    private int code;
    private String desc;

    TaskStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
    public static TaskStatusEnum getByCode(int code) {
        TaskStatusEnum[] taskStatusEnums = TaskStatusEnum.values();
        for (TaskStatusEnum taskStatusEnum : taskStatusEnums) {
            if (taskStatusEnum.getCode() == code) {
                return taskStatusEnum;
            }
        }
        throw new BizException("12", "没有匹配的taskStatus code = " + code);
    }
    public static List<TaskStatusEnum> getEndStatus() {
        TaskStatusEnum[] taskStatusEnums = TaskStatusEnum.values();
        List<TaskStatusEnum> list = new ArrayList<>();
        for (TaskStatusEnum taskStatusEnum : taskStatusEnums) {
            if (taskStatusEnum == TaskStatusEnum.stop || taskStatusEnum == TaskStatusEnum.complete) {
                list.add(taskStatusEnum);
            }
        }
        return list;
    }
    public static List<TaskStatusEnum> getUnProcessStatus() {
        List<TaskStatusEnum> taskStatusEnums = getEndStatus();
        taskStatusEnums.add(TaskStatusEnum.suspend);
        return taskStatusEnums;
    }
    public static List<Integer> getUnProcessStatusInteger() {
        return getUnProcessStatus().stream().map(TaskStatusEnum::getCode).collect(Collectors.toList());
    }
    public static List<Integer> getEndStatusInteger() {
        List<TaskStatusEnum> taskStatusEnums = getEndStatus();
        return taskStatusEnums.stream().map(TaskStatusEnum::getCode).collect(Collectors.toList());
    }
}
